local skel = fk.CreateSkill {
  name = "efengqi__tuxi",
}

Fk:loadTranslationTable{
  ["efengqi__tuxi"] = "突袭",
  [":efengqi__tuxi"] = "当你摸牌时，可以少摸任意张，获得等量角色各一张手牌。若因此没有摸牌，本回合所有角色的【闪】视为雷【杀】。",

  ["#efengqi__tuxi-choose"] = "突袭：你可以少摸至多%arg张牌，获得等量其他角色各一张手牌",
  ["#efengqi__tuxi_filter"] = "突袭",
  ["@@efengqi__tuxi"] = "突袭:闪视为雷杀",

  ["$efengqi__tuxi1"] = "快马突袭，占尽先机！",
  ["$efengqi__tuxi2"] = "马似飞影，枪如霹雳！",
}

skel:addEffect(fk.BeforeDrawCard, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return data.who == player and player:hasSkill(skel.name) and data.num > 0 and
      table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng() end)
    local tos = room:askToChoosePlayers(player, {
      min_num = 1, max_num = data.num, targets = targets, skill_name = skel.name,
      prompt = "#efengqi__tuxi-choose:::"..data.num,
    })
    if #tos > 0 then
      room:sortByAction(tos)
      event:setCostData(self, { tos = tos } )
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).tos
    for _, to in ipairs(tos) do
      if not (to.dead or to:isKongcheng()) then
        if player.dead then break end
        local c = room:askToChooseCard(player, { target = to, flag = "h", skill_name = skel.name })
        room:obtainCard(player, c, false, fk.ReasonPrey, player, skel.name)
      end
    end
    data.num = data.num - #tos
    if data.num == 0 then
      if room:getBanner("@@efengqi__tuxi") ~= 1 then
        room:doIndicate(player, room.alive_players)
        room:setBanner("@@efengqi__tuxi", 1)
        for _, p in ipairs(room.alive_players) do
          p:filterHandcards()
        end
      end
      return true
    end
  end,
})

skel:addEffect("filter", {
  card_filter = function(self, card, player)
    return player and table.contains(player:getCardIds("h"), card.id) and card.trueName== "jink"
    and Fk:currentRoom():getBanner("@@efengqi__tuxi") ~= nil
  end,
  view_as = function(self, player, card)
    local c = Fk:cloneCard("thunder__slash", card.suit, card.number)
    c.skillName = skel.name
    return c
  end,
})

skel:addEffect(fk.TurnEnd, {
  late_refresh = true,
  can_refresh = function (self, event, target, player, data)
    return player.room:getBanner("@@efengqi__tuxi") ~= nil
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setBanner("@@efengqi__tuxi", 0)
    for _, p in ipairs(player.room.alive_players) do
      p:filterHandcards()
    end
  end,
})

return skel
